<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>npm packageJson属性详解 | Keith&#39;s blog</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="icon" href="/img/favicon.png">
    <script data-ad-client="ca-pub-7828333725993554" async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <meta name="description" content="web前端技术博客,简洁至上,专注web前端学习与总结。JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github等技术文章。">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    <link rel="preload" href="/assets/css/0.styles.95a28cfa.css" as="style"><link rel="preload" href="/assets/js/app.ae5bf724.js" as="script"><link rel="preload" href="/assets/js/2.72b09a26.js" as="script"><link rel="preload" href="/assets/js/3.96877024.js" as="script"><link rel="preload" href="/assets/js/52.63e40184.js" as="script"><link rel="prefetch" href="/assets/js/10.3e431465.js"><link rel="prefetch" href="/assets/js/100.c7b84f24.js"><link rel="prefetch" href="/assets/js/101.e5a7e6f5.js"><link rel="prefetch" href="/assets/js/102.85992487.js"><link rel="prefetch" href="/assets/js/103.3f187c57.js"><link rel="prefetch" href="/assets/js/104.103d7471.js"><link rel="prefetch" href="/assets/js/105.df0063c0.js"><link rel="prefetch" href="/assets/js/106.d3f285ee.js"><link rel="prefetch" href="/assets/js/107.7ca5e73a.js"><link rel="prefetch" href="/assets/js/108.b5e1495a.js"><link rel="prefetch" href="/assets/js/109.12b39840.js"><link rel="prefetch" href="/assets/js/11.c0c2ac1e.js"><link rel="prefetch" href="/assets/js/110.2996b4eb.js"><link rel="prefetch" href="/assets/js/111.752c7e87.js"><link rel="prefetch" href="/assets/js/112.7c01a356.js"><link rel="prefetch" href="/assets/js/113.240fbeb5.js"><link rel="prefetch" href="/assets/js/114.502fae11.js"><link rel="prefetch" href="/assets/js/115.28ee11f8.js"><link rel="prefetch" href="/assets/js/116.a3f220c8.js"><link rel="prefetch" href="/assets/js/117.293dbd7c.js"><link rel="prefetch" href="/assets/js/118.7fe06c79.js"><link rel="prefetch" href="/assets/js/119.eb539041.js"><link rel="prefetch" href="/assets/js/12.0ea0beb2.js"><link rel="prefetch" href="/assets/js/120.8502bd78.js"><link rel="prefetch" href="/assets/js/121.696d358f.js"><link rel="prefetch" href="/assets/js/122.a629ef96.js"><link rel="prefetch" href="/assets/js/123.bc97cb45.js"><link rel="prefetch" href="/assets/js/124.e9dbc4a1.js"><link rel="prefetch" href="/assets/js/125.3372248a.js"><link rel="prefetch" href="/assets/js/126.58bf8057.js"><link rel="prefetch" href="/assets/js/127.532c80ac.js"><link rel="prefetch" href="/assets/js/128.a8a9dd63.js"><link rel="prefetch" href="/assets/js/129.952e36b7.js"><link rel="prefetch" href="/assets/js/13.81b38e3a.js"><link rel="prefetch" href="/assets/js/130.3f453493.js"><link rel="prefetch" href="/assets/js/131.15bb01bf.js"><link rel="prefetch" href="/assets/js/132.5e501da7.js"><link rel="prefetch" href="/assets/js/133.fbd296a8.js"><link rel="prefetch" href="/assets/js/134.a455c276.js"><link rel="prefetch" href="/assets/js/135.50985645.js"><link rel="prefetch" href="/assets/js/136.dd156bdc.js"><link rel="prefetch" href="/assets/js/137.91d77519.js"><link rel="prefetch" href="/assets/js/138.af96bbc9.js"><link rel="prefetch" href="/assets/js/139.ff60e390.js"><link rel="prefetch" href="/assets/js/14.13ff5f93.js"><link rel="prefetch" href="/assets/js/140.51ef13cd.js"><link rel="prefetch" href="/assets/js/141.2c36f0bb.js"><link rel="prefetch" href="/assets/js/142.745a5a9d.js"><link rel="prefetch" href="/assets/js/143.ef12ce5a.js"><link rel="prefetch" href="/assets/js/144.d53b8a10.js"><link rel="prefetch" href="/assets/js/145.01c80734.js"><link rel="prefetch" href="/assets/js/146.ff1abf8c.js"><link rel="prefetch" href="/assets/js/147.b334a956.js"><link rel="prefetch" href="/assets/js/148.82d1c504.js"><link rel="prefetch" href="/assets/js/149.4872ca41.js"><link rel="prefetch" href="/assets/js/15.ba6da9d5.js"><link rel="prefetch" href="/assets/js/150.eaa1b09e.js"><link rel="prefetch" href="/assets/js/151.b9deeab6.js"><link rel="prefetch" href="/assets/js/152.8914ff06.js"><link rel="prefetch" href="/assets/js/153.1c968910.js"><link rel="prefetch" href="/assets/js/154.ac2ac8e9.js"><link rel="prefetch" href="/assets/js/155.a41ac4d1.js"><link rel="prefetch" href="/assets/js/156.07ec7daa.js"><link rel="prefetch" href="/assets/js/157.d0cfaeb2.js"><link rel="prefetch" href="/assets/js/158.4a3844de.js"><link rel="prefetch" href="/assets/js/159.cd2739bf.js"><link rel="prefetch" href="/assets/js/16.bd936cd0.js"><link rel="prefetch" href="/assets/js/160.8ea34b7b.js"><link rel="prefetch" href="/assets/js/161.4bb2ece8.js"><link rel="prefetch" href="/assets/js/162.a4b2690b.js"><link rel="prefetch" href="/assets/js/163.85acbc57.js"><link rel="prefetch" href="/assets/js/164.acce92e2.js"><link rel="prefetch" href="/assets/js/165.08b51ce6.js"><link rel="prefetch" href="/assets/js/166.7ad057e5.js"><link rel="prefetch" href="/assets/js/167.2d35a768.js"><link rel="prefetch" href="/assets/js/168.b7790709.js"><link rel="prefetch" href="/assets/js/169.11b5000c.js"><link rel="prefetch" href="/assets/js/17.1d7263eb.js"><link rel="prefetch" href="/assets/js/170.d93daf1f.js"><link rel="prefetch" href="/assets/js/171.14a45c02.js"><link rel="prefetch" href="/assets/js/172.c62eb70d.js"><link rel="prefetch" href="/assets/js/173.9dd4cb5e.js"><link rel="prefetch" href="/assets/js/174.deca226f.js"><link rel="prefetch" href="/assets/js/175.eef20df3.js"><link rel="prefetch" href="/assets/js/176.c09f5a25.js"><link rel="prefetch" href="/assets/js/177.99e3a6a8.js"><link rel="prefetch" href="/assets/js/178.22bd595d.js"><link rel="prefetch" href="/assets/js/179.ef63471d.js"><link rel="prefetch" href="/assets/js/18.9412ae71.js"><link rel="prefetch" href="/assets/js/180.306daca4.js"><link rel="prefetch" href="/assets/js/181.9f8eae15.js"><link rel="prefetch" href="/assets/js/182.36cd1ffa.js"><link rel="prefetch" href="/assets/js/183.0195ae23.js"><link rel="prefetch" href="/assets/js/184.61363002.js"><link rel="prefetch" href="/assets/js/185.d01ed7e5.js"><link rel="prefetch" href="/assets/js/186.915e1946.js"><link rel="prefetch" href="/assets/js/187.392993c9.js"><link rel="prefetch" href="/assets/js/188.afcb3c55.js"><link rel="prefetch" href="/assets/js/189.99313768.js"><link rel="prefetch" href="/assets/js/19.17a0f886.js"><link rel="prefetch" href="/assets/js/190.3740a1c8.js"><link rel="prefetch" href="/assets/js/191.a8cebbb8.js"><link rel="prefetch" href="/assets/js/192.a4e4b0eb.js"><link rel="prefetch" href="/assets/js/193.f87069af.js"><link rel="prefetch" href="/assets/js/194.a83aa1ad.js"><link rel="prefetch" href="/assets/js/195.6cccc323.js"><link rel="prefetch" href="/assets/js/196.0ca74fc2.js"><link rel="prefetch" href="/assets/js/197.e57085c4.js"><link rel="prefetch" href="/assets/js/198.9d8c4195.js"><link rel="prefetch" href="/assets/js/199.e34f6d16.js"><link rel="prefetch" href="/assets/js/20.751f715d.js"><link rel="prefetch" href="/assets/js/200.4f0c1baf.js"><link rel="prefetch" href="/assets/js/201.92b5153f.js"><link rel="prefetch" href="/assets/js/202.9f5b1117.js"><link rel="prefetch" href="/assets/js/203.84c5aa3f.js"><link rel="prefetch" href="/assets/js/204.950ec43f.js"><link rel="prefetch" href="/assets/js/205.3caa1fd5.js"><link rel="prefetch" href="/assets/js/206.c5d73eeb.js"><link rel="prefetch" href="/assets/js/207.f00a7726.js"><link rel="prefetch" href="/assets/js/208.49394867.js"><link rel="prefetch" href="/assets/js/209.f891c646.js"><link rel="prefetch" href="/assets/js/21.7e3b1dd6.js"><link rel="prefetch" href="/assets/js/210.9b3ce6fe.js"><link rel="prefetch" href="/assets/js/211.22cbc362.js"><link rel="prefetch" href="/assets/js/212.5380a60a.js"><link rel="prefetch" href="/assets/js/213.64691857.js"><link rel="prefetch" href="/assets/js/214.bf089249.js"><link rel="prefetch" href="/assets/js/215.285eccf0.js"><link rel="prefetch" href="/assets/js/216.e135c2e1.js"><link rel="prefetch" href="/assets/js/217.202ec57b.js"><link rel="prefetch" href="/assets/js/218.c1b5175f.js"><link rel="prefetch" href="/assets/js/219.ac0461eb.js"><link rel="prefetch" href="/assets/js/22.67350c09.js"><link rel="prefetch" href="/assets/js/220.944daf1d.js"><link rel="prefetch" href="/assets/js/221.73cba4fb.js"><link rel="prefetch" href="/assets/js/222.cd29efdd.js"><link rel="prefetch" href="/assets/js/223.5c40831a.js"><link rel="prefetch" href="/assets/js/224.0a05890e.js"><link rel="prefetch" href="/assets/js/225.7c20df0a.js"><link rel="prefetch" href="/assets/js/226.c7f69539.js"><link rel="prefetch" href="/assets/js/227.9ccb8852.js"><link rel="prefetch" href="/assets/js/228.77bd4f2e.js"><link rel="prefetch" href="/assets/js/229.1c656481.js"><link rel="prefetch" href="/assets/js/23.308ebe55.js"><link rel="prefetch" href="/assets/js/230.a3adae2f.js"><link rel="prefetch" href="/assets/js/231.f40d7e85.js"><link rel="prefetch" href="/assets/js/232.762cdd7e.js"><link rel="prefetch" href="/assets/js/233.29242686.js"><link rel="prefetch" href="/assets/js/24.2bb08ee4.js"><link rel="prefetch" href="/assets/js/25.3f1e32c9.js"><link rel="prefetch" href="/assets/js/26.6d06f7bc.js"><link rel="prefetch" href="/assets/js/27.edfd52de.js"><link rel="prefetch" href="/assets/js/28.8c959146.js"><link rel="prefetch" href="/assets/js/29.1621b6ed.js"><link rel="prefetch" href="/assets/js/30.751b1f17.js"><link rel="prefetch" href="/assets/js/31.ec665a74.js"><link rel="prefetch" href="/assets/js/32.1b1d72d5.js"><link rel="prefetch" href="/assets/js/33.b5bd40a4.js"><link rel="prefetch" href="/assets/js/34.2155b0a7.js"><link rel="prefetch" href="/assets/js/35.d59b534a.js"><link rel="prefetch" href="/assets/js/36.44a9c35e.js"><link rel="prefetch" href="/assets/js/37.fd11aa80.js"><link rel="prefetch" href="/assets/js/38.a788fd7b.js"><link rel="prefetch" href="/assets/js/39.0099a8f6.js"><link rel="prefetch" href="/assets/js/4.ff489266.js"><link rel="prefetch" href="/assets/js/40.40c37c27.js"><link rel="prefetch" href="/assets/js/41.a1008003.js"><link rel="prefetch" href="/assets/js/42.5b767b44.js"><link rel="prefetch" href="/assets/js/43.3f71078e.js"><link rel="prefetch" href="/assets/js/44.ad24f6c3.js"><link rel="prefetch" href="/assets/js/45.25e40b16.js"><link rel="prefetch" href="/assets/js/46.b64da983.js"><link rel="prefetch" href="/assets/js/47.17f22f05.js"><link rel="prefetch" href="/assets/js/48.98ac4a14.js"><link rel="prefetch" href="/assets/js/49.2d4cfb58.js"><link rel="prefetch" href="/assets/js/5.90f8b8b3.js"><link rel="prefetch" href="/assets/js/50.961c11a7.js"><link rel="prefetch" href="/assets/js/51.c69cd332.js"><link rel="prefetch" href="/assets/js/53.ed393af3.js"><link rel="prefetch" href="/assets/js/54.e8bf699e.js"><link rel="prefetch" href="/assets/js/55.8c4b1f29.js"><link rel="prefetch" href="/assets/js/56.3ea6fad9.js"><link rel="prefetch" href="/assets/js/57.e355b934.js"><link rel="prefetch" href="/assets/js/58.591ee455.js"><link rel="prefetch" href="/assets/js/59.f75a544d.js"><link rel="prefetch" href="/assets/js/6.01e8382f.js"><link rel="prefetch" href="/assets/js/60.941e9812.js"><link rel="prefetch" href="/assets/js/61.4f56972b.js"><link rel="prefetch" href="/assets/js/62.bd0a67cc.js"><link rel="prefetch" href="/assets/js/63.5525dd5a.js"><link rel="prefetch" href="/assets/js/64.2e40b93d.js"><link rel="prefetch" href="/assets/js/65.7d7a1250.js"><link rel="prefetch" href="/assets/js/66.e88829f6.js"><link rel="prefetch" href="/assets/js/67.233ad823.js"><link rel="prefetch" href="/assets/js/68.037f0252.js"><link rel="prefetch" href="/assets/js/69.d5c49911.js"><link rel="prefetch" href="/assets/js/7.67b2aba3.js"><link rel="prefetch" href="/assets/js/70.039de8ef.js"><link rel="prefetch" href="/assets/js/71.fbbf266f.js"><link rel="prefetch" href="/assets/js/72.2cbdccb2.js"><link rel="prefetch" href="/assets/js/73.f824da30.js"><link rel="prefetch" href="/assets/js/74.c8e2bd49.js"><link rel="prefetch" href="/assets/js/75.2b326b41.js"><link rel="prefetch" href="/assets/js/76.6d52ed9a.js"><link rel="prefetch" href="/assets/js/77.6c219b3f.js"><link rel="prefetch" href="/assets/js/78.e3a6099c.js"><link rel="prefetch" href="/assets/js/79.847c1106.js"><link rel="prefetch" href="/assets/js/8.27cd446a.js"><link rel="prefetch" href="/assets/js/80.8fda2f41.js"><link rel="prefetch" href="/assets/js/81.c64976c1.js"><link rel="prefetch" href="/assets/js/82.44648201.js"><link rel="prefetch" href="/assets/js/83.a02ab71e.js"><link rel="prefetch" href="/assets/js/84.da4c143b.js"><link rel="prefetch" href="/assets/js/85.1e5083cb.js"><link rel="prefetch" href="/assets/js/86.373e4575.js"><link rel="prefetch" href="/assets/js/87.b7dae2d7.js"><link rel="prefetch" href="/assets/js/88.40e11959.js"><link rel="prefetch" href="/assets/js/89.711c7107.js"><link rel="prefetch" href="/assets/js/9.a4f4c6a7.js"><link rel="prefetch" href="/assets/js/90.36268f74.js"><link rel="prefetch" href="/assets/js/91.0b92ab60.js"><link rel="prefetch" href="/assets/js/92.9813b046.js"><link rel="prefetch" href="/assets/js/93.fcd128dd.js"><link rel="prefetch" href="/assets/js/94.c099f487.js"><link rel="prefetch" href="/assets/js/95.8042bfa3.js"><link rel="prefetch" href="/assets/js/96.45fc745f.js"><link rel="prefetch" href="/assets/js/97.32326e64.js"><link rel="prefetch" href="/assets/js/98.82035585.js"><link rel="prefetch" href="/assets/js/99.b24b3ac3.js">
    <link rel="stylesheet" href="/assets/css/0.styles.95a28cfa.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu have-body-img"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/EB-logo.png" alt="Keith's blog" class="logo"> <span class="site-name can-hide">Keith's blog</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/294b0a/" class="nav-link">个人总结</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="来自大佬的文章" class="dropdown-title"><!----> <span class="title" style="display:;">来自大佬的文章</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">前端文章</a></li><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">学习笔记</a></li></ul></li><li class="dropdown-item"><h4>页面</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-subitem"><a href="/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></li><li class="dropdown-item"><h4>技术</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-subitem"><a href="/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-subitem"><a href="/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-subitem"><a href="/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></li><li class="dropdown-item"><h4>更多</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-subitem"><a href="/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-subitem"><a href="/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-subitem"><a href="/pages/baaa02/" class="nav-link">实用技巧</a></li></ul></li><li class="dropdown-item"><!----> <a href="/about/" class="nav-link">关于</a></li><li class="dropdown-item"><!----> <a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></li><li class="dropdown-item"><h4>索引</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-subitem"><a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-subitem"><a href="/archives/" class="nav-link">归档</a></li></ul></li></ul></div></div> <a href="https://github.com/yangkeith/vuepress-theme-vdoing" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="/img/avatar.jpg"> <div class="blogger-info"><h3>Keith</h3> <span>无名小卒</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/294b0a/" class="nav-link">个人总结</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="来自大佬的文章" class="dropdown-title"><!----> <span class="title" style="display:;">来自大佬的文章</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">前端文章</a></li><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">学习笔记</a></li></ul></li><li class="dropdown-item"><h4>页面</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-subitem"><a href="/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></li><li class="dropdown-item"><h4>技术</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-subitem"><a href="/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-subitem"><a href="/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-subitem"><a href="/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></li><li class="dropdown-item"><h4>更多</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-subitem"><a href="/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-subitem"><a href="/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-subitem"><a href="/pages/baaa02/" class="nav-link">实用技巧</a></li></ul></li><li class="dropdown-item"><!----> <a href="/about/" class="nav-link">关于</a></li><li class="dropdown-item"><!----> <a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></li><li class="dropdown-item"><h4>索引</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-subitem"><a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-subitem"><a href="/archives/" class="nav-link">归档</a></li></ul></li></ul></div></div> <a href="https://github.com/yangkeith/vuepress-theme-vdoing" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>技术文档</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/9a7ee40fc232253e/" class="sidebar-link">Git使用手册</a></li><li><a href="/pages/ad247c4332211551/" class="sidebar-link">Markdown使用教程</a></li><li><a href="/pages/61f2f95fd7da14fd/" class="sidebar-link">npm常用命令</a></li><li><a href="/pages/dec4f3f00e71a312/" aria-current="page" class="active sidebar-link">npm packageJson属性详解</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#概述" class="sidebar-link">概述</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#name" class="sidebar-link">name</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#version" class="sidebar-link">version</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#description" class="sidebar-link">description</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#keywords" class="sidebar-link">keywords</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#homepage" class="sidebar-link">homepage</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#bugs" class="sidebar-link">bugs</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#license" class="sidebar-link">license</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#和用户相关的属性-author-contributors" class="sidebar-link">和用户相关的属性: author, contributors</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#files" class="sidebar-link">files</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#main" class="sidebar-link">main</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#bin" class="sidebar-link">bin</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#man" class="sidebar-link">man</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#directories" class="sidebar-link">directories</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#directories-lib" class="sidebar-link">directories.lib</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#directories-bin" class="sidebar-link">directories.bin</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#directories-man" class="sidebar-link">directories.man</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#directories-doc" class="sidebar-link">directories.doc</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#directories-example" class="sidebar-link">directories.example</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#repository" class="sidebar-link">repository</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#scripts" class="sidebar-link">scripts</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#config" class="sidebar-link">config</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#dependencies" class="sidebar-link">dependencies</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#urls-as-dependencies" class="sidebar-link">URLs as Dependencies</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#git-urls-as-dependencies" class="sidebar-link">Git URLs as Dependencies</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#github-urls" class="sidebar-link">GitHub URLs</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#local-paths" class="sidebar-link">Local Paths</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#devdependencies" class="sidebar-link">devDependencies</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#peerdependencies" class="sidebar-link">peerDependencies</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#bundleddependencies" class="sidebar-link">bundledDependencies</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#optionaldependencies" class="sidebar-link">optionalDependencies</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#engines" class="sidebar-link">engines</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#enginestrict" class="sidebar-link">engineStrict</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#os" class="sidebar-link">os</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#cpu" class="sidebar-link">cpu</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#preferglobal" class="sidebar-link">preferGlobal</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#private" class="sidebar-link">private</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#publishconfig" class="sidebar-link">publishConfig</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#default-values" class="sidebar-link">DEFAULT VALUES</a></li><li class="sidebar-sub-header"><a href="/pages/dec4f3f00e71a312/#参考文档列表-https-docs-npmjs-com" class="sidebar-link">参考文档列表(https://docs.npmjs.com/)</a></li></ul></li><li><a href="/pages/4e8444e2d534d14f/" class="sidebar-link">yaml语言教程</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>GitHub技巧</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Nodejs</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>博客搭建</span> <span class="arrow right"></span></p> <!----></section></li></ul> <div class="sidebar-slot sidebar-slot-bottom"><!-- 正方形 -->
      <ins class="adsbygoogle"
          style="display:block"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="3508773082"
          data-ad-format="auto"
          data-full-width-responsive="true"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script></div></aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-70a2d273><div class="articleInfo" data-v-70a2d273><ul class="breadcrumbs" data-v-70a2d273><li data-v-70a2d273><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-70a2d273></a></li> <li data-v-70a2d273><a href="/technology" title="技术-目录页" data-v-70a2d273>技术</a></li> <li data-v-70a2d273><a href="/technology/#技术文档" title="技术#技术文档" data-v-70a2d273>技术文档</a></li> <!----></ul> <div class="info" data-v-70a2d273><div title="作者" class="author iconfont icon-touxiang" data-v-70a2d273><a href="https://github.com/xugaoyi" target="_blank" title="作者" class="beLink" data-v-70a2d273>xugaoyi</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-70a2d273><a href="javascript:;" data-v-70a2d273>2020-04-08</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-content"></div></div></div> <h1><img src="">
          npm packageJson属性详解
        </h1> <div class="page-slot page-slot-top"><!-- 固定100% * 90px可显示，max-height:90px未见显示-->
     <ins class="adsbygoogle"
          style="display:inline-block;width:100%;max-height:90px"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="6625304284"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script></div> <div class="theme-vdoing-content content__default"><h1 id="npm-package-json属性详解"><a href="#npm-package-json属性详解" class="header-anchor">#</a> npm package.json属性详解</h1> <blockquote><p>本文转自<a href="https://www.cnblogs.com/tzyy/p/5193811.html" target="_blank" rel="noopener noreferrer">https://www.cnblogs.com/tzyy/p/5193811.html<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，作者：TZYY</p></blockquote> <h2 id="概述"><a href="#概述" class="header-anchor">#</a> 概述</h2> <p><code>package.json</code>必须是一个严格的json文件，而不仅仅是js里边的一个对象。其中很多属性可以通过<code>npm-config</code>来生成</p> <h2 id="name"><a href="#name" class="header-anchor">#</a> name</h2> <p><code>package.json</code>中最重要的属性是<code>name</code>和<code>version</code>两个属性，这两个属性是必须要有的，否则模块就无法被安装，这两个属性一起形成了一个npm模块的唯一标识符。模块中内容变更的同时，模块版本也应该一起变化。
<code>name</code>属性就是你的模块名称，下面是一些命名规则:</p> <ul><li><p><code>name</code>必须小于等于214个字节，包括前缀名称在内（如 xxx/xxxmodule）。</p></li> <li><p><code>name</code>不能以&quot;_&quot;或&quot;.&quot;开头</p></li> <li><p>不能含有大写字母</p></li> <li><p><code>name</code>会成为url的一部分，不能含有url非法字符</p> <p>下面是官网文档的一些建议：</p></li> <li><p>不要使用和node核心模块一样的名称</p></li> <li><p><code>name</code>中不要含有&quot;js&quot;和&quot;node&quot;。 It's assumed that it's js, since you're writing a package.json file, and you can specify the engine using the &quot;engines&quot; field. (See below.)</p></li> <li><p><code>name</code>属性会成为模块url、命令行中的一个参数或者一个文件夹名称，任何非url安全的字符在name中都不能使用，也不能以&quot;_&quot;或&quot;.&quot;开头</p></li> <li><p><code>name</code>属性也许会被写在<code>require()</code>的参数中，所以最好取个简短而语义化的值。</p></li> <li><p>创建一个模块前可以先到后边的网址查查<code>name</code>是否已经被占用. <a href="https://www.npmjs.com/" target="_blank" rel="noopener noreferrer">https://www.npmjs.com/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <ul><li><div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 发布一个包的时候，需要检验某个包名是否存在</span>
<span class="token function">npm</span> search <span class="token operator">&lt;</span>ModuleName<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div></li></ul></li></ul> <p><code>name</code>属性可以有一些前缀如 e.g. @myorg/mypackage.在npm-scope(7)的文档中可以看到详细说明</p> <h2 id="version"><a href="#version" class="header-anchor">#</a> version</h2> <p><code>version</code>必须可以被npm依赖的一个<code>node-semver</code>模块解析。具体规则见下面的<code>dependencies</code>模块</p> <h2 id="description"><a href="#description" class="header-anchor">#</a> description</h2> <p>一个描述，方便别人了解你的模块作用，搜索的时候也有用。</p> <h2 id="keywords"><a href="#keywords" class="header-anchor">#</a> keywords</h2> <p>一个字符串数组，方便别人搜索到本模块</p> <h2 id="homepage"><a href="#homepage" class="header-anchor">#</a> homepage</h2> <p>项目主页url
<strong>注意:</strong> 这个项目主页url和url属性不同，如果你填写了url属性，npm注册工具会认为你把项目发布到其他地方了，获取模块的时候不会从npm官方仓库获取，而是会重定向到url属性配置的地址。
（原文档中用了 spit(吐)这个单词，作者表示他不是在开玩笑:）</p> <h2 id="bugs"><a href="#bugs" class="header-anchor">#</a> bugs</h2> <p>填写一个bug提交地址或者一个邮箱，被你的模块坑到的人可以通过这里吐槽，例如：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;url&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;https://github.com/owner/project/issues&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;email&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;project@hostname.com&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>url和email可以任意填或不填，如果只填一个，可以直接写成一个字符串而不是对象。如果填写了url，npm bugs命令会使用这个url。</p> <h2 id="license"><a href="#license" class="header-anchor">#</a> license</h2> <p>你应该为你的模块制定一个协议，让用户知道他们有何权限来使用你的模块，以及使用该模块有哪些限制。最简单的，例如你用BSD-3-Clause 或 MIT之类的协议，如下：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> <span class="token property">&quot;license&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;MIT&quot;</span> <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>你可以在<a href="https://spdx.org/licenses/" target="_blank" rel="noopener noreferrer">https://spdx.org/licenses/ <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>这个地址查阅协议列表 。</p> <h2 id="和用户相关的属性-author-contributors"><a href="#和用户相关的属性-author-contributors" class="header-anchor">#</a> 和用户相关的属性: author, contributors</h2> <p><code>author</code>是一个码农， <code>contributors</code>是一个码农数组。 <code>person</code>是一个有一些描述属性的对象，如下 like this:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;Barney Rubble&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;email&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;b@rubble.com&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;url&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;http://barnyrubble.tumblr.com/&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>也可以按如下格式缩写，npm会帮着转换:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>&quot;Barney Rubble b@rubble.com (http://barnyrubble.tumblr.com/)&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><code>email</code>和<code>url</code>属性实际上都是可以省略的。描述用户信息的还有一个<code>maintainers</code>（维护者）属性。</p> <h2 id="files"><a href="#files" class="header-anchor">#</a> files</h2> <p><code>files</code>属性的值是一个数组，内容是模块下文件名或者文件夹名，如果是文件夹名，则文件夹下所有的文件也会被包含进来（除非文件被另一些配置排除了）
你也可以在模块根目录下创建一个<code>.npmignore</code>文件（windows下无法直接创建以&quot;.&quot;开头的文件，使用linux命令行工具创建如git bash），写在这个文件里边的文件即便被写在files属性里边也会被排除在外，这个文件的写法&quot;.gitignore&quot;类似。</p> <h2 id="main"><a href="#main" class="header-anchor">#</a> main</h2> <p><code>main</code>属性指定了程序的主入口文件。意思是，如果你的模块被命名为foo，用户安装了这个模块并通过require(&quot;foo&quot;)来使用这个模块，那么require返回的内容就是main属性指定的文件中 module.exports指向的对象。
它应该指向模块根目录下的一个文件。对大对数模块而言，这个属性更多的是让模块有一个主入口文件，然而很多模块并不写这个属性。</p> <h2 id="bin"><a href="#bin" class="header-anchor">#</a> bin</h2> <p>很多模块有一个或多个需要配置到PATH路径下的可执行模块，npm让这个工作变得十分简单（实际上npm本身也是通过bin属性安装为一个可执行命令的）
如果要用npm的这个功能，在package.json里边配置一个bin属性。bin属性是一个已命令名称为key，本地文件名称为value的map如下：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;bin&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">&quot;myapp&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;./cli.js&quot;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>模块安装的时候，若是全局安装，则npm会为bin中配置的文件在bin目录下创建一个软连接（对于windows系统，默认会在C:\Users\username\AppData\Roaming\npm目录下），若是局部安装，则会在项目内的./node_modules/.bin/目录下创建一个软链接。
因此，按上面的例子，当你安装myapp的时候，npm就会为cli.js在/usr/local/bin/myapp路径创建一个软链接。
如果你的模块只有一个可执行文件，并且它的命令名称和模块名称一样，你可以只写一个字符串来代替上面那种配置，例如：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> 
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;my-program&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1.2.5&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;bin&quot;</span><span class="token operator">:</span> <span class="token string">&quot;./path/to/program&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>作用和如下写法相同:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> 
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;my-program&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1.2.5&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;bin&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span> 
        <span class="token property">&quot;my-program&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;./path/to/program&quot;</span> 
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="man"><a href="#man" class="header-anchor">#</a> man</h2> <p>制定一个或通过数组制定一些文件来让linux下的man命令查找文档地址。
如果只有一个文件被指定的话，安装后直接使用man+模块名称，而不管man指定的文件的实际名称。例如:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;foo&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;version&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;1.2.3&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;description&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;A packaged foo fooer for fooing foos&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;main&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;foo.js&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;man&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;./man/doc.1&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>通过man foo命令会得到 ./man/doc.1 文件的内容。
如果man文件名称不是以模块名称开头的，安装的时候会给加上模块名称前缀。因此，下面这段配置：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> 
    <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;foo&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;version&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;1.2.3&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;description&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;A packaged foo fooer for fooing foos&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;main&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;foo.js&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;man&quot;</span> <span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">&quot;./man/foo.1&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;./man/bar.1&quot;</span> <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>会创建一些文件来作为man foo和man foo-bar命令的结果。
man文件必须以数字结尾，或者如果被压缩了，以.gz结尾。数字表示文件将被安装到man的哪个部分。</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> 
    <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;foo&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;version&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;1.2.3&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;description&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;A packaged foo fooer for fooing foos&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;main&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;foo.js&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;man&quot;</span> <span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">&quot;./man/foo.1&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;./man/foo.2&quot;</span> <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>会创建 man foo 和 man 2 foo 两条命令。</p> <h2 id="directories"><a href="#directories" class="header-anchor">#</a> directories</h2> <p>CommonJs通过directories来制定一些方法来描述模块的结构，看看npm的package.json文件https://registry.npmjs.org/npm/latest ，可以发现里边有这个字段的内容。
<img src="http://zoucz.com/blogimgs/2016-02-16/1455624810992.png" alt="img">
目前这个配置没有任何作用，将来可能会整出一些花样来。</p> <h3 id="directories-lib"><a href="#directories-lib" class="header-anchor">#</a> directories.lib</h3> <p>告诉用户模块中lib目录在哪，这个配置目前没有任何作用，但是对使用模块的人来说是一个很有用的信息。</p> <h3 id="directories-bin"><a href="#directories-bin" class="header-anchor">#</a> directories.bin</h3> <p>如果你在这里指定了bin目录，这个配置下面的文件会被加入到bin路径下，如果你已经在package.json中配置了bin目录，那么这里的配置将不起任何作用。</p> <h3 id="directories-man"><a href="#directories-man" class="header-anchor">#</a> directories.man</h3> <p>指定一个目录，目录里边都是man文件，这是一种配置man文件的语法糖。</p> <h3 id="directories-doc"><a href="#directories-doc" class="header-anchor">#</a> directories.doc</h3> <p>在这个目录里边放一些markdown文件，可能最终有一天它们会被友好的展现出来（应该是在npm的网站上）</p> <h3 id="directories-example"><a href="#directories-example" class="header-anchor">#</a> directories.example</h3> <p>放一些示例脚本，或许某一天会有用 - -！</p> <h2 id="repository"><a href="#repository" class="header-anchor">#</a> repository</h2> <p>指定一个代码存放地址，对想要为你的项目贡献代码的人有帮助。像这样：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token property">&quot;repository&quot;</span> <span class="token operator">:</span>
  <span class="token punctuation">{</span>
      <span class="token property">&quot;type&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;git&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;url&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;https://github.com/npm/npm.git&quot;</span>
  <span class="token punctuation">}</span>

<span class="token property">&quot;repository&quot;</span> <span class="token operator">:</span>
  <span class="token punctuation">{</span> 
      <span class="token property">&quot;type&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;svn&quot;</span><span class="token punctuation">,</span> 
      <span class="token property">&quot;url&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;https://v8.googlecode.com/svn/trunk/&quot;</span>
  <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>若你的模块放在GitHub, GitHub gist, Bitbucket, or GitLab的仓库里，npm install的时候可以使用缩写标记来完成：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token property">&quot;repository&quot;</span><span class="token operator">:</span> <span class="token string">&quot;npm/npm&quot;</span>

<span class="token property">&quot;repository&quot;</span><span class="token operator">:</span> <span class="token string">&quot;gist:11081aaa281&quot;</span>

<span class="token property">&quot;repository&quot;</span><span class="token operator">:</span> <span class="token string">&quot;bitbucket:example/repo&quot;</span>

<span class="token property">&quot;repository&quot;</span><span class="token operator">:</span> <span class="token string">&quot;gitlab:another/repo&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="scripts"><a href="#scripts" class="header-anchor">#</a> scripts</h2> <p>scripts属性是一个对象，里边指定了项目的生命周期个各个环节需要执行的命令。key是生命周期中的事件，value是要执行的命令。
具体的内容有 install start stop 等，详见<a href="https://docs.npmjs.com/misc/scripts" target="_blank" rel="noopener noreferrer"> https://docs.npmjs.com/misc/scripts<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h2 id="config"><a href="#config" class="header-anchor">#</a> config</h2> <p>用来设置一些项目不怎么变化的项目配置，例如port等。
用户用的时候可以使用如下用法：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>http.createServer(...).listen(process.env.npm_package_config_port)
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>可以通过npm config set foo:port 80来修改config。详见<a href="https://docs.npmjs.com/misc/config" target="_blank" rel="noopener noreferrer">https://docs.npmjs.com/misc/config<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> 
    <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;foo&quot;</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;config&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">&quot;port&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;8080&quot;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="dependencies"><a href="#dependencies" class="header-anchor">#</a> dependencies</h2> <p>dependencies属性是一个对象，配置模块依赖的模块列表，key是模块名称，value是版本范围，版本范围是一个字符，可以被一个或多个空格分割。
dependencies也可以被指定为一个git地址或者一个压缩包地址。
不要把测试工具或transpilers写到dependencies中。 下面是一些写法，详见<a href="https://docs.npmjs.com/misc/semver" target="_blank" rel="noopener noreferrer">https://docs.npmjs.com/misc/semver<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <ul><li>version 精确匹配版本</li> <li>&gt;version 必须大于某个版本</li> <li>&gt;=version 大于等于</li> <li>&lt;version 小于</li> <li>&lt;=versionversion 小于</li> <li>~version &quot;约等于&quot;，具体规则详见semver文档</li> <li>^version &quot;兼容版本&quot;具体规则详见semver文档</li> <li>1.2.x 仅一点二点几的版本</li> <li>http://... 见下面url作为denpendencies的说明</li> <li><ul><li>任何版本</li></ul></li> <li>&quot;&quot; 空字符，和*相同</li> <li>version1 - version2 相当于 &gt;=version1 &lt;=version2.</li> <li>range1 || range2 范围1和范围2满足任意一个都行</li> <li>git... 见下面git url作为denpendencies的说明</li> <li>user/repo See 见下面GitHub仓库的说明</li> <li>tag 发布的一个特殊的标签，见npm-tag的文档 <a href="https://docs.npmjs.com/getting-started/using-tags" target="_blank" rel="noopener noreferrer">https://docs.npmjs.com/getting-started/using-tags<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>path/path/path 见下面本地模块的说明
下面的写法都是可以的:</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> <span class="token property">&quot;dependencies&quot;</span> <span class="token operator">:</span>
  <span class="token punctuation">{</span> <span class="token property">&quot;foo&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;1.0.0 - 2.9999.9999&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;bar&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;&gt;=1.0.2 &lt;2.1.2&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;baz&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;&gt;1.0.2 &lt;=2.3.4&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;boo&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;2.0.1&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;qux&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;&lt;1.0.0 || &gt;=2.3.1 &lt;2.4.5 || &gt;=2.5.2 &lt;3.0.0&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;asd&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;http://asdf.com/asdf.tar.gz&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;til&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;~1.2&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;elf&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;~1.2.3&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;two&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;2.x&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;thr&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;3.3.x&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;lat&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;latest&quot;</span>
  <span class="token punctuation">,</span> <span class="token property">&quot;dyl&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;file:../dyl&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h2 id="urls-as-dependencies"><a href="#urls-as-dependencies" class="header-anchor">#</a> URLs as Dependencies</h2> <p>在版本范围的地方可以写一个url指向一个压缩包，模块安装的时候会把这个压缩包下载下来安装到模块本地。</p> <h2 id="git-urls-as-dependencies"><a href="#git-urls-as-dependencies" class="header-anchor">#</a> Git URLs as Dependencies</h2> <p>Git url可以像下面一样:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>git://github.com/user/project.git#commit-ish
git+ssh://user@hostname:project.git#commit-ish
git+ssh://user@hostname/project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>commit-ish 可以是任意标签，哈希值，或者可以检出的分支，默认是master分支。</p> <h2 id="github-urls"><a href="#github-urls" class="header-anchor">#</a> GitHub URLs</h2> <p>支持github的 username/modulename 的写法，#后边可以加后缀写明分支hash或标签：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;foo&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;0.0.0&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;dependencies&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;express&quot;</span><span class="token operator">:</span> <span class="token string">&quot;visionmedia/express&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;mocha&quot;</span><span class="token operator">:</span> <span class="token string">&quot;visionmedia/mocha#4727d357ea&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="local-paths"><a href="#local-paths" class="header-anchor">#</a> Local Paths</h2> <p>npm2.0.0版本以上可以提供一个本地路径来安装一个本地的模块，通过npm install xxx --save 来安装，格式如下：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>../foo/bar
~/foo/bar
./foo/bar
/foo/bar
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>package.json 生成的相对路径如下:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;baz&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;dependencies&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;bar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;file:../foo/bar&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>这种属性在离线开发或者测试需要用npm install的情况，又不想自己搞一个npm server的时候有用，但是发布模块到公共仓库时不应该使用这种属性。</p> <h2 id="devdependencies"><a href="#devdependencies" class="header-anchor">#</a> devDependencies</h2> <p>如果有人想要下载并使用你的模块，也许他们并不希望或需要下载一些你在开发过程中使用的额外的测试或者文档框架。
在这种情况下，最好的方法是把这些依赖添加到devDependencies属性的对象中。
这些模块会在npm link或者npm install的时候被安装，也可以像其他npm配置一样被管理，详见npm的config文档。
对于一些跨平台的构建任务，例如把CoffeeScript编译成JavaScript，就可以通过在package.json的script属性里边配置prepublish脚本来完成这个任务，然后需要依赖的coffee-script模块就写在devDependencies属性种。
例如:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ethopia-waza&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;description&quot;</span><span class="token operator">:</span> <span class="token string">&quot;a delightfully fruity coffee varietal&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1.2.3&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;devDependencies&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;coffee-script&quot;</span><span class="token operator">:</span> <span class="token string">&quot;~1.6.3&quot;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;scripts&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;prepublish&quot;</span><span class="token operator">:</span> <span class="token string">&quot;coffee -o lib/ -c src/waza.coffee&quot;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;main&quot;</span><span class="token operator">:</span> <span class="token string">&quot;lib/waza.js&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>prepublish脚本会在发布之前运行，因此用户在使用之前就不用再自己去完成编译的过程了。在开发模式下，运行npm install也会执行这个脚本（见npm script文档），因此可以很方便的调试。</p> <h2 id="peerdependencies"><a href="#peerdependencies" class="header-anchor">#</a> peerDependencies</h2> <p>有时候做一些插件开发，比如grunt等工具的插件，它们往往是在grunt的某个版本的基础上开发的，而在他们的代码中并不会出现require(&quot;grunt&quot;)这样的依赖，dependencies配置里边也不会写上grunt的依赖，为了说明此模块只能作为插件跑在宿主的某个版本范围下，可以配置peerDependencies：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;tea-latte&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1.3.5&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;peerDependencies&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;tea&quot;</span><span class="token operator">:</span> <span class="token string">&quot;2.x&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>上面这个配置确保再npm install的时候tea-latte会和2.x版本的tea一起安装，而且它们两个的依赖关系是同级的：
├── tea-latte@1.3.5
└── tea@2.2.0
这个配置的目的是让npm知道，如果要使用此插件模块，请确保安装了兼容版本的宿主模块。</p> <h2 id="bundleddependencies"><a href="#bundleddependencies" class="header-anchor">#</a> bundledDependencies</h2> <p>上面的单词少个d，写成bundleDependencies也可以。
指定发布的时候会被一起打包的模块。</p> <h2 id="optionaldependencies"><a href="#optionaldependencies" class="header-anchor">#</a> optionalDependencies</h2> <p>如果一个依赖模块可以被使用， 同时你也希望在该模块找不到或无法获取时npm继续运行，你可以把这个模块依赖放到optionalDependencies配置中。这个配置的写法和dependencies的写法一样，不同的是这里边写的模块安装失败不会导致npm install失败。
当然，这种模块就需要你自己在代码中处理模块确实的情况了，例如：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">try</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> foo <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'foo'</span><span class="token punctuation">)</span>
  <span class="token keyword">var</span> fooVersion <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'foo/package.json'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>version
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span>er<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  foo <span class="token operator">=</span> <span class="token keyword">null</span>
<span class="token punctuation">}</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">notGoodFooVersion</span><span class="token punctuation">(</span>fooVersion<span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
  foo <span class="token operator">=</span> <span class="token keyword">null</span>
<span class="token punctuation">}</span>

<span class="token comment">// .. then later in your program ..</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span>foo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  foo<span class="token punctuation">.</span><span class="token function">doFooThings</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>optionalDependencies 中的配置会覆盖dependencies中的配置，最好只在一个地方写。</p> <h2 id="engines"><a href="#engines" class="header-anchor">#</a> engines</h2> <p>你可以指定项目运行的node版本范围，如下：
{ &quot;engines&quot; : { &quot;node&quot; : &quot;&gt;=0.10.3 &lt;0.12&quot; } }
和dependencies一样，如果你不指定版本范围或者指定为*，任何版本的node都可以。
也可以指定一些npm版本可以正确的安装你的模块，例如：
{ &quot;engines&quot; : { &quot;npm&quot; : &quot;~1.0.20&quot; } }
要注意的是，除非你设置了engine-strict属性，engines属性是仅供参考的。</p> <h2 id="enginestrict"><a href="#enginestrict" class="header-anchor">#</a> engineStrict</h2> <p>注意：这个属性已经弃用，将在npm 3.0.0 版本干掉。</p> <h2 id="os"><a href="#os" class="header-anchor">#</a> os</h2> <p>可以指定你的模块只能在哪个操作系统上跑：
&quot;os&quot; : [ &quot;darwin&quot;, &quot;linux&quot; ]
也可以指定黑名单而不是白名单：
&quot;os&quot; : [ &quot;!win32&quot; ]
服务的操作系统是由process.platform来判断的，这个属性允许黑白名单同时存在，虽然没啥必要这样搞...</p> <h2 id="cpu"><a href="#cpu" class="header-anchor">#</a> cpu</h2> <p>限制模块只能在某某cpu架构下运行
&quot;cpu&quot; : [ &quot;x64&quot;, &quot;ia32&quot; ]
同样可以设置黑名单:
&quot;cpu&quot; : [ &quot;!arm&quot;, &quot;!mips&quot; ]
cpu架构通过 process.arch 判断</p> <h2 id="preferglobal"><a href="#preferglobal" class="header-anchor">#</a> preferGlobal</h2> <p>如果您的软件包主要用于安装到全局的命令行应用程序，那么该值设置为true ，如果它被安装在本地，则提供一个警告。实际上该配置并没有阻止用户把模块安装到本地，只是防止该模块被错误的使用引起一些问题。</p> <h2 id="private"><a href="#private" class="header-anchor">#</a> private</h2> <p>如果这个属性被设置为true，npm将拒绝发布它，这是为了防止一个私有模块被无意间发布出去。如果你只想让模块被发布到一个特定的npm仓库，如一个内部的仓库，可与在下面的publishConfig中配置仓库参数。</p> <h2 id="publishconfig"><a href="#publishconfig" class="header-anchor">#</a> publishConfig</h2> <p>这个配置是会在模块发布时用到的一些值的集合。如果你不想模块被默认被标记为最新的，或者默认发布到公共仓库，可以在这里配置tag或仓库地址。</p> <h2 id="default-values"><a href="#default-values" class="header-anchor">#</a> DEFAULT VALUES</h2> <p>npm设置了一些默认参数，如：
&quot;scripts&quot;: {&quot;start&quot;: &quot;node server.js&quot;}
如果模块根目录下有一个server.js文件，那么npm start会默认运行这个文件。
&quot;scripts&quot;:{&quot;preinstall&quot;: &quot;node-gyp rebuild&quot;}
如果模块根目录下有binding.gyp, npm将默认用node-gyp来编译preinstall的脚本
&quot;contributors&quot;: [...]
若模块根目录下有AUTHORS 文件，则npm会按Name (url)格式解析每一行的数据添加到contributors中，可以用#添加行注释</p> <h2 id="参考文档列表-https-docs-npmjs-com"><a href="#参考文档列表-https-docs-npmjs-com" class="header-anchor">#</a> 参考文档列表(https://docs.npmjs.com/)</h2> <p>semver(7)
npm-init(1)
npm-version(1)
npm-config(1)
npm-config(7)
npm-help(1)
npm-faq(7)
npm-install(1)
npm-publish(1)
npm-rm(1)</p></div></div> <div class="page-slot page-slot-bottom"><!-- 横向自适应 -->
      <ins class="adsbygoogle"
          style="display:block"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="6620245489"
          data-ad-format="auto"
          data-full-width-responsive="true"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script></div> <div class="page-edit"><!----> <!----> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/61f2f95fd7da14fd/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">npm常用命令</div></a> <a href="/pages/4e8444e2d534d14f/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">yaml语言教程</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/61f2f95fd7da14fd/" class="prev">npm常用命令</a></span> <span class="next"><a href="/pages/4e8444e2d534d14f/">yaml语言教程</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/dcedab/"><div>Nginx配置https转http</div></a> <span>12-10</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/82baa3/"><div>使用State Hook</div></a> <span>04-06</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/72710d/"><div>使用Effect Hook</div></a> <span>04-06</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><!----> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2021-2022
    <span><div style="width:300px;margin:0 auto; padding:20px 0;"><a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=13019902000398" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;"><img src="" style="float:left;"/><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">冀公网安备 13019902000398号</p></a></div></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <div class="body-bg" style="background:url() center center / cover no-repeat;opacity:0.5;"></div> <!----> <div class="custom-html-window custom-html-window-rb" style="display:;"><div class="custom-wrapper"><i class="close-but">×</i> <div><!-- 固定160*160px -->
      <ins class="adsbygoogle"
          style="display:inline-block;max-width:160px;max-height:160px"
          data-ad-client="ca-pub-7828333725993554"
          data-ad-slot="8377369658"></ins>
      <script>
          (adsbygoogle = window.adsbygoogle || []).push({});
      </script>
      </div></div></div></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.ae5bf724.js" defer></script><script src="/assets/js/2.72b09a26.js" defer></script><script src="/assets/js/3.96877024.js" defer></script><script src="/assets/js/52.63e40184.js" defer></script>
  </body>
</html>